package Presentacion.Proveedores.ABMProveedores;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JTextField;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;

import java.awt.Checkbox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JTextPane;
import javax.swing.JScrollPane;

import Logica.Administracion.ABMIvaAlicuotaLogica;
import Logica.Proveedores.ABMProveedorLogica;
import Logica.Util.Validacion;
import Modelo.IvaAlicuota;
import Modelo.Proveedor;

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.util.List;

public class ABMProveedores extends JFrame {

	private JPanel contentPane;
	private JTextField tfDescripcionComercial;
	private JTextField tfNombreFantasia;
	private JTextField tfNroDeCUIT;
	private JTextField tfNroIngBruto;
	private JTextField tfDescuentoFlete;
	private JTextField tfIDProveedor;
	private JTextField tfDireccion;
	private JTextField tfUbicacion;
	private JTextField tfNroTelefono;
	private JTextField tfEMail;
	private JTextField tfContacto;
	private JTextPane textPane;
	private JScrollPane scroll;
	private JButton btnImpProveedor, btnGrabarActualizar, btnNuevoProveedor;
	private JButton btnUltimo, btnDerecho, btnBuscar, btnIzquierdo, btnPrimero;
	private JComboBox cbIVA;
	
	
	
	
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ABMProveedores frame = new ABMProveedores();
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ABMProveedores() {
		setResizable(false);
		setTitle("Alta, Baja o Modificaci\u00F3n de Proveedores");
		this.setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		/**Pregunto si al presionar la "X" esta seguro de que quiere cerrar la ventana.*/
		this.addWindowListener(new WindowAdapter() {
	           public void windowClosing(WindowEvent e) {
	        	   setDefaultCloseOperation(0); 
	        	   cerrarVentana();
	           }
	       });
		
		setBounds(100, 100, 660, 600);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(192, 192, 192));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblDatosComerciales = new JLabel("Datos Comerciales");
		lblDatosComerciales.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblDatosComerciales.setBounds(10, 11, 191, 27);
		contentPane.add(lblDatosComerciales);
		
		JSeparator separator1 = new JSeparator();
		separator1.setBounds(10, 34, 520, 7);
		contentPane.add(separator1);
		
		JLabel lblDenominacionComercial = new JLabel("Denominaci\u00F3n comercial");
		lblDenominacionComercial.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblDenominacionComercial.setBounds(10, 49, 191, 14);
		contentPane.add(lblDenominacionComercial);
		
		tfDescripcionComercial = new JTextField();
		tfDescripcionComercial.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfDescripcionComercial);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfDescripcionComercial);
			}
		});
		
		tfDescripcionComercial.setToolTipText("");
		tfDescripcionComercial.setBounds(232, 45, 290, 25);
		contentPane.add(tfDescripcionComercial);
		tfDescripcionComercial.setColumns(10);
		
		JLabel lblNombreFantasia = new JLabel("Nombre fantas\u00EDa");
		lblNombreFantasia.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblNombreFantasia.setBounds(10, 78, 123, 14);
		contentPane.add(lblNombreFantasia);
		
		tfNombreFantasia = new JTextField();
		tfNombreFantasia.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfNombreFantasia);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfNombreFantasia);
			}
		});
		tfNombreFantasia.setToolTipText("");
		tfNombreFantasia.setColumns(10);
		tfNombreFantasia.setBounds(182, 74, 340, 25);
		contentPane.add(tfNombreFantasia);
		
		JLabel lblCodigoDeBarra = new JLabel("C\u00F3digo de Barra");
		lblCodigoDeBarra.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblCodigoDeBarra.setBounds(10, 115, 200, 27);
		contentPane.add(lblCodigoDeBarra);
		
		JLabel lblDireccion = new JLabel("Direcci\u00F3n:");
		lblDireccion.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblDireccion.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDireccion.setBounds(20, 155, 113, 14);
		contentPane.add(lblDireccion);
		
		JLabel lblUbicacion = new JLabel("Ubicaci\u00F3n:");
		lblUbicacion.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblUbicacion.setHorizontalAlignment(SwingConstants.RIGHT);
		lblUbicacion.setBounds(20, 180, 113, 14);
		contentPane.add(lblUbicacion);
		
		JLabel lblNroTelefono = new JLabel("Nro. de Tel\u00E9fono:");
		lblNroTelefono.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblNroTelefono.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNroTelefono.setBounds(10, 205, 123, 14);
		contentPane.add(lblNroTelefono);
		
		JLabel lblEMail = new JLabel("@ Mail:");
		lblEMail.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblEMail.setHorizontalAlignment(SwingConstants.RIGHT);
		lblEMail.setBounds(20, 230, 113, 14);
		contentPane.add(lblEMail);
		
		JLabel lblValorizacionArticulo = new JLabel("Valorizaci\u00F3n del Art\u00EDculo");
		lblValorizacionArticulo.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblValorizacionArticulo.setBounds(10, 308, 267, 27);
		contentPane.add(lblValorizacionArticulo);
		
		JSeparator separator2 = new JSeparator();
		separator2.setBounds(10, 331, 520, 7);
		contentPane.add(separator2);
		
		btnPrimero = new JButton("");
		btnPrimero.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				init(getFirst().getId());
			}
		});
		btnPrimero.setIcon(new ImageIcon(ABMProveedores.class.getResource("/Presentacion/Img/primero.png")));
		btnPrimero.setToolTipText("Principio");
		btnPrimero.setBounds(570, 49, 70, 70);
		contentPane.add(btnPrimero);
		
		btnIzquierdo = new JButton("");
		btnIzquierdo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				init(getPre(Integer.parseInt(tfIDProveedor.getText())).getId());
			}
		});
		btnIzquierdo.setIcon(new ImageIcon(ABMProveedores.class.getResource("/Presentacion/Img/izquierda.png")));
		btnIzquierdo.setToolTipText("Anterior");
		btnIzquierdo.setBounds(570, 119, 70, 70);
		contentPane.add(btnIzquierdo);
		
		btnBuscar = new JButton("");
		btnBuscar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				buscar();
			}
		});
		btnBuscar.setIcon(new ImageIcon(ABMProveedores.class.getResource("/Presentacion/Img/binoculars.png")));
		btnBuscar.setToolTipText("Buscar");
		btnBuscar.setBounds(570, 189, 70, 70);
		contentPane.add(btnBuscar);
		
		btnDerecho = new JButton("");
		btnDerecho.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				init(getPos(Integer.parseInt(tfIDProveedor.getText())).getId());
			}
		});
		btnDerecho.setIcon(new ImageIcon(ABMProveedores.class.getResource("/Presentacion/Img/derecha.png")));
		btnDerecho.setToolTipText("Siguiente");
		btnDerecho.setBounds(570, 259, 70, 70);
		contentPane.add(btnDerecho);
		
		btnUltimo = new JButton("");
		btnUltimo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				init(getLast().getId());
			}
		});
		btnUltimo.setIcon(new ImageIcon(ABMProveedores.class.getResource("/Presentacion/Img/ultimo.png")));
		btnUltimo.setToolTipText("Ultimo");
		btnUltimo.setBounds(570, 329, 70, 70);
		contentPane.add(btnUltimo);
		
		JLabel lblNroDeCUIT = new JLabel("Nro. de CUIT:");
		lblNroDeCUIT.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblNroDeCUIT.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNroDeCUIT.setBounds(221, 379, 100, 15);
		contentPane.add(lblNroDeCUIT);
		
		JLabel lblNroIngBruto = new JLabel("Nro. Ingreso Bruto");
		lblNroIngBruto.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblNroIngBruto.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNroIngBruto.setBounds(201, 411, 120, 15);
		contentPane.add(lblNroIngBruto);
		
		tfNroDeCUIT = new JTextField();
		tfNroDeCUIT.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfNroDeCUIT);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfNroDeCUIT);
			}
		});
		tfNroDeCUIT.setHorizontalAlignment(SwingConstants.CENTER);
		tfNroDeCUIT.setBounds(349, 377, 170, 20);
		contentPane.add(tfNroDeCUIT);
		tfNroDeCUIT.setColumns(10);
		
		tfNroIngBruto = new JTextField();
		tfNroIngBruto.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfNroIngBruto);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfNroIngBruto);
			}
		});
		tfNroIngBruto.setHorizontalAlignment(SwingConstants.CENTER);
		tfNroIngBruto.setForeground(new Color(255, 0, 0));
		tfNroIngBruto.setColumns(10);
		tfNroIngBruto.setBounds(349, 408, 170, 20);
		contentPane.add(tfNroIngBruto);
		
		JLabel lblDescuentoFlete = new JLabel("Descuento de flete:");
		lblDescuentoFlete.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblDescuentoFlete.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDescuentoFlete.setBounds(207, 284, 140, 15);
		contentPane.add(lblDescuentoFlete);
		
		tfDescuentoFlete = new JTextField();
		tfDescuentoFlete.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfDescuentoFlete);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfDescuentoFlete);
			}
		});
		tfDescuentoFlete.setHorizontalAlignment(SwingConstants.CENTER);
		tfDescuentoFlete.setColumns(10);
		tfDescuentoFlete.setBounds(358, 281, 85, 20);
		contentPane.add(tfDescuentoFlete);
		
		JLabel lblIVA = new JLabel("IVA");
		lblIVA.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblIVA.setHorizontalAlignment(SwingConstants.RIGHT);
		lblIVA.setBounds(232, 351, 80, 15);
		contentPane.add(lblIVA);
		
		cbIVA = new JComboBox();
		cbIVA.setBounds(322, 349, 200, 20);
		contentPane.add(cbIVA);
		
		JLabel lblFechaUltimaCompra = new JLabel("");
		lblFechaUltimaCompra.setBounds(315, 375, 85, 14);
		contentPane.add(lblFechaUltimaCompra);
		
		btnNuevoProveedor = new JButton("Nuevo Proveedor");
		btnNuevoProveedor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				nuevo();
			}
		});
		btnNuevoProveedor.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnNuevoProveedor.setBounds(10, 530, 150, 30);
		contentPane.add(btnNuevoProveedor);
		
		btnGrabarActualizar = new JButton("Grabar / Actualizar");
		btnGrabarActualizar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				grabarActualizar();
			}
		});
		btnGrabarActualizar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnGrabarActualizar.setBounds(200, 530, 150, 30);
		contentPane.add(btnGrabarActualizar);
		
		btnImpProveedor = new JButton("Imp. Proveedor");
		btnImpProveedor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		btnImpProveedor.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnImpProveedor.setBounds(390, 530, 150, 30);
		contentPane.add(btnImpProveedor);
		
		tfIDProveedor = new JTextField();
		tfIDProveedor.setFont(new Font("Tahoma", Font.BOLD, 14));
		tfIDProveedor.setHorizontalAlignment(SwingConstants.CENTER);
		tfIDProveedor.setEditable(false);
		tfIDProveedor.setBounds(182, 45, 40, 25);
		contentPane.add(tfIDProveedor);
		tfIDProveedor.setColumns(10);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(6, 140, 520, 7);
		contentPane.add(separator);
		
		JLabel lblContacto = new JLabel("Contacto:");
		lblContacto.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContacto.setFont(new Font("Dialog", Font.PLAIN, 13));
		lblContacto.setBounds(20, 256, 113, 14);
		contentPane.add(lblContacto);
		
		tfDireccion = new JTextField();
		tfDireccion.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfDireccion);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfDireccion);
			}
		});
		tfDireccion.setBounds(143, 151, 300, 20);
		contentPane.add(tfDireccion);
		tfDireccion.setColumns(10);
		
		tfUbicacion = new JTextField();
		tfUbicacion.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfUbicacion);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfUbicacion);
			}
		});
		tfUbicacion.setColumns(10);
		tfUbicacion.setBounds(143, 178, 300, 20);
		contentPane.add(tfUbicacion);
		
		tfNroTelefono = new JTextField();
		tfNroTelefono.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfNroTelefono);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfNroTelefono);
			}
		});
		tfNroTelefono.setColumns(10);
		tfNroTelefono.setBounds(143, 203, 300, 20);
		contentPane.add(tfNroTelefono);
		
		tfEMail = new JTextField();
		tfEMail.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfEMail);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfEMail);
			}
		});
		tfEMail.setColumns(10);
		tfEMail.setBounds(143, 228, 300, 20);
		contentPane.add(tfEMail);
		
		tfContacto = new JTextField();
		tfContacto.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(tfContacto);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(tfContacto);
			}
		});
		tfContacto.setColumns(10);
		tfContacto.setBounds(143, 254, 300, 20);
		contentPane.add(tfContacto);
		
		JLabel lblObservaciones = new JLabel("Observaciones");
		lblObservaciones.setBounds(10, 346, 113, 14);
		contentPane.add(lblObservaciones);
		
		scroll = new JScrollPane();
		scroll.setBounds(10, 374, 200, 145);
		contentPane.add(scroll);
		
		textPane = new JTextPane();
		textPane.addFocusListener(new FocusAdapter() {			
			public void focusGained(FocusEvent arg0) {
				pintaVerde(textPane);
			}			
			public void focusLost(FocusEvent arg0) {
				pintaBlanco(textPane);
			}
		});
		scroll.setViewportView(textPane);
		
		this.init(getFirst().getId());
		
	}
	
	/*Metodo para confirma si esta seguro que quiere cerrar la aplicacinn*/	
	public void cerrarVentana(){
					this.dispose();			    
	}
	
//  ** Pinto JTEXTFIELD de color   **  // 
  public void pintaVerde(JTextField tf){
		tf.setBackground(new Color(153, 255, 153));
	}	
	public void pintaBlanco(JTextField tf){
		tf.setBackground(new Color(255, 255, 255));
	}

//  ** Pinto JTEXTPANE de color   **  // 
  public void pintaVerde(JTextPane tp){
		tp.setBackground(new Color(153, 255, 153));
	}	
	public void pintaBlanco(JTextPane tp){
		tp.setBackground(new Color(255, 255, 255));
	}
	
	public void init(int id){
			Proveedor a = ABMProveedorLogica.getById(id);				
			//cargo los textfield
			tfIDProveedor.setText(Integer.toString(a.getId()));
			tfDescripcionComercial.setText(a.getNombre());
			tfNombreFantasia.setText(a.getFantacia());
			tfDireccion.setText(a.getDir());
			tfUbicacion.setText(a.getUbi());
			tfNroTelefono.setText(a.getTel());
			tfEMail.setText(a.getMail());
			tfContacto.setText(a.getContacto());
			tfNroDeCUIT.setText(a.getCuit());
			tfNroIngBruto.setText(a.getIngB());
			textPane.setText(a.getObs());
			//cargo los combobox
			this.initIVA();
	}
	
	public void initIVA(){
    	if(cbIVA.getItemCount() == 0){   	
	        List<IvaAlicuota>listIVA = null;
	        listIVA = ABMIvaAlicuotaLogica.getList();
	         
	        cbIVA.removeAllItems();
	        cbIVA.addItem("0.00");
	        for(int i = 0; i <listIVA.size(); i++) {
	                String a = listIVA.get(i).getValor().toString();
	                cbIVA.addItem(a); 
	           } 
    	}else{
    		
    		}
        }
	
	public Proveedor getPos(int id){
		return ABMProveedorLogica.getPos(id);
	}	
	public Proveedor getPre(int id){
		return ABMProveedorLogica.getPre(id);
	}
	public Proveedor getLast(){
		return ABMProveedorLogica.getLast();
	}
	
	public Proveedor getFirst(){
		return ABMProveedorLogica.getFirst();
	}
	
	public void buscar(){
		new BuscarProveedor(this);
	}
	
	public void grabarActualizar(){
		try {
			if(tfDescripcionComercial.getText().length() == 0 || tfNombreFantasia.getText().length() == 0)
//				tfCodigoBarra.setText("");
				throw new Exception();
			int id = ABMProveedorLogica.getById(Integer.parseInt(tfIDProveedor.getText())).getId();
			int count = ABMProveedorLogica.countByNom(tfDescripcionComercial.getText());
			Proveedor f = null;
			if (id == 0 && count == 0 ) //nuevo
				crear();
			
			if(id == 0 && count == 1)
				JOptionPane.showMessageDialog(null, "No se pudo crear el proveedor \n ERROR: Objeto existente",
						  "Error", JOptionPane.ERROR_MESSAGE);
			
			if(id != 0 && count == 1){
				f = ABMProveedorLogica.getByNom(tfDescripcionComercial.getText());
				if (id == f.getId())
					modificar();
				else
					JOptionPane.showMessageDialog(null, "No se pudo modificar el proveedor \n ERROR: Objeto existente",
							  "Error", JOptionPane.ERROR_MESSAGE);
			}
				
			if(id != 0 && count == 0)
				modificar();
			
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, "No se pudo crear el proveedor \n ERROR: completar descripciones",
					  "Error", JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		}		
	}
	
	public void crear(){
		Proveedor obj = this.asignar();
		ABMProveedorLogica.crear(obj);
	}
	
	public void modificar(){
		Proveedor obj = this.asignar();		
		ABMProveedorLogica.modificar(obj);
	}
	
	public Proveedor asignar(){
		Proveedor obj;
		this.validar();
		//textfield
		obj = ABMProveedorLogica.getByNom(tfDescripcionComercial.getText().toUpperCase());
		obj.setId(Integer.parseInt(tfIDProveedor.getText()));
		obj.setFantacia(tfNombreFantasia.getText().toUpperCase());
		obj.setNombre(tfDescripcionComercial.getText().toUpperCase());
		obj.setDir(tfDireccion.getText().toUpperCase());
		obj.setUbi(tfUbicacion.getText().toUpperCase());
		obj.setTel(tfNroTelefono.getText().toUpperCase());
		obj.setMail(tfEMail.getText().toUpperCase());
		obj.setContacto(tfContacto.getText().toUpperCase());		
		obj.setFlete(Double.parseDouble(tfDescuentoFlete.getText()));
		obj.setCuit(tfNroDeCUIT.getText());
		obj.setIngB(tfNroIngBruto.getText());
		obj.setObs(textPane.getText());			
		
		return obj;		
	}
	
	
	public void validar(){
		if (tfDescripcionComercial.getText().length() == 0)
			tfDescripcionComercial.setText("");
		if(!Validacion.esNuM(tfIDProveedor.getText()))
			tfIDProveedor.setText("0");
		if (tfNombreFantasia.getText().length() == 0)
			tfNombreFantasia.setText("");
		if (tfDireccion.getText().length() == 0)
			tfDireccion.setText("");
		if (tfUbicacion.getText().length() == 0)
			tfUbicacion.setText("");
		if (tfNroTelefono.getText().length() == 0)
			tfNroTelefono.setText("");
		if (tfEMail.getText().length() == 0)
			tfEMail.setText("");
		if (tfContacto.getText().length() == 0)
			tfContacto.setText("");
		if (tfNroDeCUIT.getText().length() == 0)
			tfNroDeCUIT.setText("");
		if (tfNroIngBruto.getText().length() == 0)
			tfNroIngBruto.setText("");
		if (textPane.getText().length() == 0)
			textPane.setText("");
		
		tfDescuentoFlete.setText(tfDescuentoFlete.getText().replace(",", "."));
		if(!Validacion.esReal(tfDescuentoFlete.getText())){
			tfDescuentoFlete.setText("0");
		}			
	}
	
	public void nuevo(){
		try {
			Proveedor last = ABMProveedorLogica.getLast();			
			tfIDProveedor.setText(Integer.toString(last.getId() +1));
			tfDescripcionComercial.setText("");
			tfNombreFantasia.setText("");
			tfDireccion.setText("");
			tfUbicacion.setText("");	
			tfNroTelefono.setText("");
			tfContacto.setText("");
			tfDescuentoFlete.setText("");
			tfNroDeCUIT.setText("");
			tfNroIngBruto.setText("");			
			
			//cargo los combobox
			cbIVA.setSelectedIndex(0);			
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
}
